package com.demo.util.excel.builders;

import lombok.Data;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

@Data
public class ExcelStyleBuilder {

    private Map<String, Function<XSSFWorkbook, XSSFCellStyle>> getStyleMap = new HashMap<>();

    public ExcelStyleBuilder add(String name, Function<XSSFWorkbook, XSSFCellStyle> getStyleFunc) {
        getStyleMap.put(name, getStyleFunc);
        return this;
    }

    public Map<String, XSSFCellStyle> done(@NotNull XSSFWorkbook workbook) {
        Map<String, XSSFCellStyle> styleMap = new HashMap<>();
        getStyleMap.forEach((name, getStyleFunc) -> {
            styleMap.put(name, getStyleFunc.apply(workbook));
        });
        return styleMap;
    }

}
